# 1. 给定一个字典，把它的键和值互换，返回一个新字典
dict1 = {'a': 100, 'b': 200, 'c': 300}
dict1 = {value: key for key, value in dict1.items()}
print(dict1)
# 2. 给定两个字典，合并成一个字典，相同的键的值相加
dict1 = {'a': 100, 'b': 200, 'c': 300}
dict2 = {'b': 150, 'c': 250, 'd': 400}
dict3 = {key: dict1.get(key, 0) + dict2.get(key, 0) for key in list(dict1.keys())+list(dict2.keys())}
print(dict3)
# 3. 给定一个字符串，统计其中每个字符出现的次数，返回一个字典
a_string = 'hello world'
count_dict = {char: a_string.count(char) for char in a_string}
print(count_dict)
# 4. 给定一个列表，统计其中每个元素出现的次数
a_list = [1, 1, 2, 3, 3, 3, 'a', 'b', 'b', 'b']
a_dict = {key: a_list.count(key) for key in a_list}
print(a_dict)
